package org.to_zero.ssm.sdm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.to_zero.ssm.sdm.entity.Sign;
import org.to_zero.ssm.sdm.entity.vo.ResponseEntity;
import org.to_zero.ssm.sdm.mapper.SignMapper;
import org.to_zero.ssm.sdm.service.SignService;

import java.util.List;
import java.util.Objects;

@Service
public class SignServiceImpl implements SignService {

    @Autowired
    private SignMapper signMapper;

    @Override
    public ResponseEntity findNotSignList(Integer teamId) {
        return ResponseEntity.success(signMapper.findNotSignList(teamId));
    }

    @Override
    public ResponseEntity saveSignList(List<Sign> signList) {
        int flg = signMapper.insertSignList(signList);
        return flg > 0 ? ResponseEntity.success(flg + "人完成了签到") : ResponseEntity.error("出现了一些问题/(ㄒoㄒ)/~~");
    }

    @Override
    public ResponseEntity findSignList(Sign sign) {
        return ResponseEntity.success(signMapper.findSignCondition(sign));
    }

    @Override
    public ResponseEntity update(Sign sign) {
        int flg = 0;
        if (Objects.nonNull(sign.getId())) {
            flg = signMapper.updateByPrimaryKeySelective(sign);
        } else {
            flg = signMapper.insertSelective(sign);
        }
        return flg > 0 ? ResponseEntity.success("更新成功") : ResponseEntity.error("出了一点问题/(ㄒoㄒ)/~~");
    }

    @Override
    public ResponseEntity deleteById(Integer id) {
        int flg = signMapper.deleteByPrimaryKey(id);
        return flg > 0 ? ResponseEntity.success("删除成功") : ResponseEntity.error("出了一点问题/(ㄒoㄒ)/~~");
    }

    @Override
    public ResponseEntity deleteByIds(Integer[] ids) {
        int flg = signMapper.deleteByPrimaryKeys(ids);
        return flg > 0 ? ResponseEntity.success("批量删除成功") : ResponseEntity.error("出了一点问题/(ㄒoㄒ)/~~");
    }
}
